<?php
/**
 * Created by zhang.
 * User: zhang
 * Date: 2018/7/24
 * Time: 21:54
 *
 * 酒吧申请控制器
 */

namespace app\index\controller;


use app\index\model\barManager;
use think\Config;

class ApplyBarManager extends  Base
{


    private $uplaodurl = '/uploads/barimage/';
    private $urlconfig;

    public function __construct()
    {
        $this->urlconfig = Config::get('queue.url');

    }

    public function applyBarShow(){
        return view();
    }


    public function uploadeApplyImage(){
        $file = request()->file('file');

        // 移动到框架应用根目录/public/uploads/ 目录下
        if($file){
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/barimage');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
//                echo $info->getExtension();
//                // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
//                echo $info->getSaveName();
//                // 输出 42a79759f284b767dfcb2a0197904287.jpg
//                echo $info->getFilename();
                //"status": 1,
               // "url": "http://image.uisdc.com/wp-content/uploads/2017/05/homestarrunner.jpg"
                echo  json_encode(['status'=>1,'url'=>$this->urlconfig. $this->uplaodurl.$info->getSaveName()]);
                exit;
            }else{
                // 上传失败获取错误信息
                echo $file->getError();
                exit;
            }
        }
    }


    public function addApplyInfo(){

        $info['apply_bar_name']= request()->post('barname');
        $info['apply_name'] = request()->post('applyname');
        $info['apply_provinve'] = request()->post('s_province');
        $info['apply_city'] = request()->post('s_city');
        $info['apply_country'] = request()->post('s_county');
        $info['apply_info'] = request()->post('content');
        $info['apply_address'] = request()->post('alladdress');
        $info['apply_time'] = date('y-m-d H:i:s',time());
        $info['apply_stat'] = 1;
        $info['apply_user_id'] = $this ->userid;

        $result = (new barManager())->insert($info);
        if($result){
            echo json_encode(['status'=>1]);
        }else{
            echo json_encode(['status'=>0]);
        }
        exit;
    }

}